// SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
// SPDX-License-Identifier: GPL-3.0-only

package core

import (
	"context"
)

type ImageReferenceInfo struct {
	GroupName   string `json:"groupName"`
	ImageName   string `json:"imageName"`
	Reference   string `json:"reference"`
	TimeStamp   int64  `json:"timeStamp"`
	ContentType string `json:"contentType"`
	Content     string `json:"content"`
	Digest      string `json:"digest"`
}

type ImageReferenceInfoList []*ImageReferenceInfo

func (a ImageReferenceInfoList) Len() int           { return len(a) }
func (a ImageReferenceInfoList) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ImageReferenceInfoList) Less(i, j int) bool { return a[i].TimeStamp < a[j].TimeStamp }

type ImageReferenceDao interface {
	Insert(ctx context.Context, imageRefInfo *ImageReferenceInfo) error
	Exist(ctx context.Context, groupName, imageName, reference string) (bool, error)
	Get(ctx context.Context, groupName, imageName, reference string) (*ImageReferenceInfo, error)
	Update(ctx context.Context, imageRefInfo *ImageReferenceInfo) error
	Remove(ctx context.Context, groupName, imageName, reference string) error
	RemoveByImage(ctx context.Context, groupName, imageName string) error
	Count(ctx context.Context, groupName, imageName string, includeDigest bool) (uint32, error)
	List(ctx context.Context, groupName, imageName string, includeDigest bool) ([]*ImageReferenceInfo, error)
	ListAll(ctx context.Context) ([]*ImageReferenceInfo, error)
}
